package collection;

import ooday05.Point;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * 泛型的演示
 */
public class GennericDemo {
    public static void main(String[] args) {
        Collection<String>c=new ArrayList<>();//泛型集合
        c.add("one");
        c.add("two");
        c.add("three");
        c.add("four");
        //  c.add(123);编译错误，123的类型违背了集合C所指向的泛型的实际类型String；

        Iterator<String>it=c.iterator();
        while (it.hasNext()){
            String str=it.next();
            System.out.println(str);
        }

        for (String str:c){
            System.out.println(str);
        }



        Collection<PointCol>a=new ArrayList<>();
        a.add(new PointCol(1,2));
        a.add(new PointCol(3,4));

        Iterator<PointCol> qq=a.iterator();
        while (qq.hasNext()){
            PointCol p=qq.next();
            System.out.println(p);
        }

        for (PointCol p:a){
            System.out.println(p);
        }


    }
}
